package com.osdp.startup;

import com.osdp.common.listener.TokenContextListener;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.client.RestTemplate;

/**
 * java -jar target/micro-uc-0.0.1-SNAPSHOT.jar
 * java -jar target/micro-uc-0.0.1-SNAPSHOT.jar --server.port=9001
 * java -jar target/micro-uc-0.0.1-SNAPSHOT.jar --server.port=9002
 *  EnableDiscoveryClient 服务发现，可支持其他的注册中心
 *  EnableEurekaClient 服务发现 支持Eureka注册中心
 *  https://spring.io/projects/spring-cloud
 *  https://spring.io/projects/spring-cloud-openfeign
 *  https://github.com/spring-cloud-samples/feign-eureka
 *
 *  *因为在启动类上使用EnableFeignClients来开启Feign的功能。
 *  EnableFeignClients也有个basePackages,配置上{"org.noak"}启动后测试，成功了。
 *  ps: 如果有fallback 需要 加上@ComponentScan(basePackages={"org.noak"}) 才能启动
 * @author liubo
 *
 */
@SpringBootApplication(scanBasePackages = "com.osdp",exclude = {org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class})
@MapperScan("com.osdp.*.mapper")
//@ServletComponentScan
//@EnableAsync
@EnableDiscoveryClient
@EnableFeignClients(basePackages="com.osdp.*.feign")//这里一定要加basePackages，不然会报找不feignclient服务
//@EnableCircuitBreaker
@ComponentScan(basePackages = {"com.osdp"})
public class MicroUcApplication {
	
	public static void main(String[] args) {
		SpringApplication.run(MicroUcApplication.class, args);
	}

	//	@Bean
//	public SaveSqlInterceptor getSaveSqlInterceptor(){
//		return new SaveSqlInterceptor();
//	}

	@Bean
	@LoadBalanced
	public RestTemplate restTemplate(){
		return new RestTemplate();
	}

	@Bean
	public TokenContextListener tokenContextListener(){
		return new TokenContextListener();
	}
}
